package com.jinjunhuang.memoryopt;

import android.content.Context;
import android.widget.Toast;

import java.lang.ref.WeakReference;

/**
 * @author jianjunhuang.me@foxmail.com
 *         create on 2017/11/18.
 */

public class SingleInstance {
    private static SingleInstance singleInstance;

    private WeakReference<Context> weakContext = null;

    private SingleInstance(Context context) {
        weakContext = new WeakReference<Context>(context);
    }

    public static SingleInstance getInstance(Context context) {
        if (singleInstance == null) {
            singleInstance = new SingleInstance(context);
        }
        return singleInstance;
    }

    public SingleInstance getInstance() {
        if (singleInstance == null) {
//            singleInstance = new SingleInstance(context);
        }
        return singleInstance;
    }

//    public void init(Context context) {
//        this.context = context;
//    }

    public void show() {
        Toast.makeText(weakContext.get(), "aaaa", Toast.LENGTH_SHORT).show();
    }

}
